home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / muds / pennmush.000 / pennmush-1.50-p8-linux.tar / pennmush / unparse.c < prev    next >
C/C++ Source or Header  |  1993-04-01  |  4KB  |  132 lines

  1. /* unparse.c */
  2.  
  3. #include <string.h>
  4. #include "config.h"
  5. #include "db.h"
  6. #include "externs.h"
  7. #include "interface.h"
  8.  
  9. const char *real_unparse(player, loc, obey_myopic)
  10.      dbref player;
  11.      dbref loc;
  12.      int obey_myopic;
  13. {
  14.     static char buf[BUFFER_LEN];
  15.  
  16.     Access(loc);
  17.     switch (loc) {
  18.       case NOTHING:
  19.     return "*NOTHING*";
  20.       case HOME:
  21.     return "*HOME*";
  22.       default:
  23.     if ((Can_Examine(player, loc) || can_link_to(player, loc) ||
  24.          IS(loc, TYPE_ROOM, ROOM_JUMP_OK) || (Flags(loc) & CHOWN_OK) ||
  25.          IS(loc, TYPE_THING, THING_DEST_OK)) && 
  26.         (!Myopic(player) || !obey_myopic)) {
  27.         /* show everything */
  28.         sprintf(buf, "%s(#%d%s)", Name(loc), loc,
  29.             unparse_flags(loc, player));
  30.         return buf;
  31.     } else {
  32.         /* show only the name */
  33.         return Name(loc);
  34.     }
  35.     }
  36. }
  37.  
  38. static char boolexp_buf[BUFFER_LEN];
  39. static char *buftop;
  40.  
  41. static void unparse_boolexp1(player, b, outer_type, flag)
  42.     dbref player;
  43.     struct boolexp *b;
  44.     boolexp_type outer_type;
  45.     int flag;    /*  0 is full unparse, 1 is numbers-only */
  46. {
  47.   char tbuf1[BUFFER_LEN];
  48.  
  49.   if (b == TRUE_BOOLEXP) {
  50.     safe_str((char *)"*UNLOCKED*", boolexp_buf, &buftop);
  51.     return;
  52.   } else {
  53.     switch (b->type) {
  54.       case BOOLEXP_AND:
  55.     if (outer_type == BOOLEXP_NOT) {
  56.       safe_chr('(', boolexp_buf, &buftop);
  57.     }
  58.     unparse_boolexp1(player, b->sub1, b->type, flag);
  59.     safe_chr(AND_TOKEN, boolexp_buf, &buftop);
  60.     unparse_boolexp1(player, b->sub2, b->type, flag);
  61.     if (outer_type == BOOLEXP_NOT) {
  62.       safe_chr(')', boolexp_buf, &buftop);
  63.     }
  64.     break;
  65.       case BOOLEXP_OR:
  66.     if (outer_type == BOOLEXP_NOT || outer_type == BOOLEXP_AND) {
  67.       safe_chr('(', boolexp_buf, &buftop);
  68.     }
  69.     unparse_boolexp1(player, b->sub1, b->type, flag);
  70.     safe_chr(OR_TOKEN, boolexp_buf, &buftop);
  71.     unparse_boolexp1(player, b->sub2, b->type, flag);
  72.     if (outer_type == BOOLEXP_NOT || outer_type == BOOLEXP_AND) {
  73.       safe_chr(')', boolexp_buf, &buftop);
  74.     }
  75.     break;
  76.       case BOOLEXP_IND:
  77.     safe_chr(AT_TOKEN, boolexp_buf, &buftop);
  78.     unparse_boolexp1(player, b->sub1, b->type, flag);
  79.     break;
  80.       case BOOLEXP_IS:
  81.     safe_chr(IS_TOKEN, boolexp_buf, &buftop);
  82.     unparse_boolexp1(player, b->sub1, b->type, flag);
  83.     break;
  84.       case BOOLEXP_CARRY:
  85.     safe_chr(IN_TOKEN, boolexp_buf, &buftop);
  86.     unparse_boolexp1(player, b->sub1, b->type, flag);
  87.     break;
  88.       case BOOLEXP_OWNER:
  89.     safe_chr(OWNER_TOKEN, boolexp_buf, &buftop);
  90.     unparse_boolexp1(player, b->sub1, b->type, flag);
  91.     break;
  92.       case BOOLEXP_NOT:
  93.     safe_chr(NOT_TOKEN, boolexp_buf, &buftop);
  94.     unparse_boolexp1(player, b->sub1, b->type, flag);
  95.     break;
  96.       case BOOLEXP_CONST:
  97.     if (flag) {
  98.       sprintf(tbuf1, "#%d", b->thing);
  99.       safe_str(tbuf1, boolexp_buf, &buftop);
  100.     } else
  101.       safe_str(unparse_object(player, b->thing), boolexp_buf, &buftop);
  102.     break;
  103.       case BOOLEXP_ATR:
  104.     sprintf(tbuf1, "%s:%s", b->atr_lock->name,
  105.         uncompress(b->atr_lock->text));
  106.     safe_str(tbuf1, boolexp_buf, &buftop);
  107.     break;
  108.       case BOOLEXP_EVAL:
  109.     sprintf(tbuf1, "%s/%s", b->atr_lock->name,
  110.         uncompress(b->atr_lock->text));
  111.     safe_str(tbuf1, boolexp_buf, &buftop);
  112.     break;
  113.       default:
  114.     safe_str((char *)"Bad boolexp type!", boolexp_buf, &buftop);
  115.     fprintf(stderr, "ERROR: unparse_boolexp1 bad boolexp type on #%d\n",
  116.         player);
  117.     break;
  118.       }
  119.   }
  120. }
  121.  
  122. const char *unparse_boolexp(player, b, flag)
  123.     dbref player;
  124.     struct boolexp *b;
  125.     int flag;    /*  0 is full unparse, 1 is numbers-only */
  126. {
  127.   buftop = boolexp_buf;
  128.   unparse_boolexp1(player, b, BOOLEXP_CONST, flag);    /* no outer type */
  129.   *buftop++ = '\0';
  130.   return boolexp_buf;
  131. }
  132.